/**
 * field_month
 */
layui.define(['YunjField','laydate'], function (exports) {

    let YunjField = layui.YunjField;
    let laydate = layui.laydate;

    class YunjMonth extends YunjField {

        constructor(options={}) {
            super(options);
        }

        defineExtraArgs(){
            let that = this;
            return {
                placeholder:"",
                format:"yyyy-MM",
                min:"",
                max:"",
                range:false,
                disabled:false
            };
        }

        layoutControl() {
            let that = this;
            let controlHtml = `<input type="text" name="${that.id}" placeholder="${that.args.placeholder}" 
                                    class="layui-input" autocomplete="off" readonly style="cursor:pointer;">`;
            return `<div class="layui-input-inline yunj-input-inline">${controlHtml}</div>`;
        }

        setValue(val=''){
            let that=this;
            that.fieldBoxEl.find(`input:text[name=${that.id}]`).val(val);
        }

        getValue(){
            let that=this;
            return that.fieldBoxEl.find(`input:text[name=${that.id}]`).val();
        }

        renderDone(){
            let that = this;
            if(that.args.disabled) return;
            let args = {
                elem: `input[name=${that.id}]`,
                type: 'month',
                format: that.args.format,
                range: (yunj.isString(that.args.range) || yunj.isBool(that.args.range) ? that.args.range : false),
                trigger: 'click',
            };
            if (that.args.min) args.min = that.args.min;
            if (that.args.max) args.min = that.args.max;
            laydate.render(args);
        }

    }

    exports('field_month', YunjMonth);
});